﻿using System.Collections.Generic;
using System.Data;
using System;
using SXT.Party.WomenAndChildrens.Model;

namespace ZHDJ.MobileInterface
{
    public partial class GetPartyWCNewViewList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            WCNewViewListOutParam result = new WCNewViewListOutParam();
            WCNewViewListInParam param = new WCNewViewListInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as WCNewViewListInParam;

                if (isFlag)
                {
                    if (param.page_no * param.page_count <= 0)
                    {
                        result.code = "0";
                        result.desc = "当前页,以及页记录条数必须为大于0的正整数";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    DataSet ds = PartyWCExpertExpoReleaseInfo.GetGridData(param.KeyWord, param.Type, param.page_no, param.page_count, "1", " data.IsTop desc", "True");

                    if (ds != null && ds.Tables.Count == 2)
                    {
                        WCNewView itemTemp;
                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[1].Rows[0][0]), param.page_count);
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            itemTemp = new WCNewView();
                            itemTemp.ExpoID = dr["ExpoID"].ToString();
                            itemTemp.Title = dr["Title"].ToString();
                            itemTemp.Keywords = dr["Keywords"].ToString();
                            itemTemp.Author = dr["Author"].ToString();
                            itemTemp.Age = dr["Age"].ToString();
                            itemTemp.Content = dr["Content"].ToString();
                            itemTemp.Content = itemTemp.Content.Replace("src=\"/fs/UploadFiles/Party", "src=\"http://www.ith71.cn/fs/UploadFiles/party");
                            itemTemp.Content = itemTemp.Content.Replace("src=\"/fs/UploadFiles/party", "src=\"http://www.ith71.cn/fs/UploadFiles/party");
                            itemTemp.CreateTime = dr["CreateTime"].ToString();
                            itemTemp.TypeName = dr["ParaMemberName"].ToString();
                            result.data.list.Add(itemTemp);
                        }
                    }
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetPartyWCNewViewList", SerializeHelper.JsonSerializer<WCNewViewListInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<WCNewViewListInParam, WCNewViewListOutParam>();
            else
                SafeProcessRequest<WCNewViewListInParam, WCNewViewListOutParam>();
        }
    }

    #region 请求参数
    public class WCNewViewListInParam
    {
        /// <summary>
        /// 关键字
        /// </summary>
        public string KeyWord
        { get; set; }

        /// <summary>
        /// 类型
        /// </summary>
        public string Type
        { get; set; }

        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class WCNewViewListOutParam
    {
        public WCNewViewListOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new WCNewViewList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 专家来支招
        /// </summary>
        public WCNewViewList data
        { get; set; }
    }

    public class WCNewViewList
    {
        public WCNewViewList()
        {
            total_pages = 0;
            list = new List<WCNewView>();
        }

        public List<WCNewView> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }

    /// <summary>
    /// 专家来支招
    /// </summary>
    public class WCNewView
    {
        /// <summary>
        ///	论点ID		
        /// </summary>
        public string ExpoID
        { get; set; }



        /// <summary>
        ///	主题			
        /// </summary>
        public string Title
        { get; set; }

        /// <summary>
        ///	关键字		
        /// </summary>
        public string Keywords
        { get; set; }

        /// <summary>
        ///	作者			
        /// </summary>
        public string Author
        { get; set; }

        /// <summary>
        ///	年龄段			
        /// </summary>
        public string Age
        { get; set; }

        /// <summary>
        ///	内容			
        /// </summary>
        public string Content
        { get; set; }

        /// <summary>
        ///	类型			
        /// </summary>
        public string TypeName
        { get; set; }

        /// <summary>
        ///	创建时间			
        /// </summary>
        public string CreateTime
        { get; set; }
    }
    #endregion
}